package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.webservice.AttrsIn;
import com.chinanet.utils.webservice.ITMSWebService;

import java.util.HashMap;
import java.util.Map;

/**
 * ITMS_WebService_Imp_feedbackWorkTicketsInfo
 * ITMS-绑定关系查询
 * @author xuzhi
 *
 */
public class ITMS_WebService_Imp_feedbackWorkTicketsInfo implements WorkInterFace {

	@Override
	public String getName() {
		return "ITMS-绑定关系查询";
	}

	@Override
	public String getDesciption() {
		return "";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in=new Attr[2];
		in[0]=new Attr("work_id","操作流水号；对应电子运维的工单主单流水号（选填）",AttrType.TYPE_String,true);
		in[1]=new Attr("loid","终端SN号(必填)", AttrType.TYPE_String,true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[10];
		out[0]=new Attr("ReturnCode", "0：成功；其它：失败", AttrType.TYPE_Int, true);
		out[1]=new Attr("return", "返回return", AttrType.TYPE_String, true);
		out[2]=new Attr("work_id", "操作流水号,对应移动运维的工单流水号", AttrType.TYPE_String, true);
		out[3]=new Attr("loid", "逻辑ID", AttrType.TYPE_String, true);
		out[4]=new Attr("serial_number", "设备序列号；当该LOID未与SN绑定时,该值可以为空.", AttrType.TYPE_String, true);
		out[5]=new Attr("service_status", "服务是否开通；0: ITMS注册成功。1: ITMS未开通业务。 （电子运维提示为“LOID 号XXX在ITMS系统未注册”）2: 非法的LOID。（电子运维提示为“LOID 号XXX在ITMS系统为非法”）", AttrType.TYPE_String, true);
		out[6]=new Attr("service_list", "已开通业务的列表", AttrType.TYPE_String, true);
		out[7]=new Attr("error_msg", "错误信息", AttrType.TYPE_String, true);
		out[8]=new Attr("log", "服务器返回的soapxml", AttrType.TYPE_String, true);
		out[9]=new Attr("Errormsg", "服务器返回的错误信息,当ReturnCode为0的时候就不必去读取", AttrType.TYPE_String, false);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {
		AttrsIn attrsIn=new AttrsIn();
		ITMSWebService webService=new ITMSWebService();
		Map<String,Object> map=new HashMap<String, Object>();
		//Get into arguments
		attrsIn.setFunctionName("feedbackWorkTicketsInfo");
		attrsIn.setRequestMessage("<work_id>"+webService.dealString((String) data.get("work_id"))+"</work_id>" +
				"<LOID_ARRAY>"+
	            "<loid>"+webService.dealString((String) data.get("loid"))+"</loid>" +
	            "</LOID_ARRAY>");
		//Get soapxml
		String returnXml=webService.WebServiceInit(attrsIn,1);
		String flag=webService.getPattern("return", returnXml);
		
		if(flag.length()>0){
			map.put("ReturnCode", 0);
			map.put("return", webService.getPattern("return", returnXml));
			map.put("work_id", webService.getPattern("work_id", returnXml));
			map.put("loid", webService.getPattern("loid", returnXml));
			map.put("serial_number", webService.getPattern("serial_number", returnXml));
			map.put("service_status", webService.getPattern("service_status", returnXml));
			map.put("service_list", webService.getPattern("service_list", returnXml));
			map.put("error_msg", webService.getPattern("error_msg", returnXml));
			map.put("log", returnXml);
			map.put("Errormsg", "");
		}else{
			map.put("ReturnCode", 1);
			map.put("return", "");
			map.put("work_id", "");
			map.put("loid", "");
			map.put("serial_number", "");
			map.put("service_status", "");
			map.put("service_list", "");
			map.put("error_msg", "");
			map.put("log", returnXml);
			map.put("Errormsg", "网元侧执行出错，处理请求失败");
		}
		
		return map;
	}

}
